package com.yzc.mihuyou.controller;


import com.yzc.mihuyou.entity.Popup;
import com.yzc.mihuyou.entity.User;
import com.yzc.mihuyou.service.PopupService;
import com.yzc.mihuyou.util.TokenProccessor;
import com.yzc.mihuyou.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 资源表 前端控制器
 * </p>
 *
 * @author yzc
 * @since 2022-05-16
 */
@RestController
@RequestMapping("/mihuyou/popup")
public class PopupController {

    @Autowired
    PopupService popupService;
    @Autowired
    TokenProccessor tokenProccessor;

    @PostMapping("addPos")
    public JsonResult addPos(@RequestBody Popup popup, HttpServletRequest request){
        String token = request.getHeader("token");
        User user=null;
        if(token!=null){
            user= tokenProccessor.verify(token);
        }
        if(user==null){
          return   new JsonResult(400,"未登录");
        }
        popup.setUserId(user.getUserId()+"");
        return  new JsonResult(200,"成功",popupService.addSele(popup));
    }
    @GetMapping("selPos")
    public  JsonResult selPos(int id){
        Map<String,Object>map=new HashMap<>();
        map.put("puser",popupService.selSeke(id));
        return  new JsonResult(200,"查询成功",map);
    }
}
